package pers.xhh.frontapi.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import pers.xhh.frontapi.entity.MiUserEntity;

import java.util.Date;

/**
 * @author wei-xhh
 * @date 2020-11-22
 */
public class TokenUtils {

    public static String getToken(MiUserEntity miUserEntity) {
        String token="";
        // 1天
        long expireTime = 60 * 1000 * 60 * 24;
        token= JWT.create().withAudience("" + miUserEntity.getUserId())
                .withExpiresAt(new Date(System.currentTimeMillis() + expireTime))
                .sign(Algorithm.HMAC256(miUserEntity.getPassword()));
        return token;
    }
}
